<?php


require_once dirname(__FILE__).'/../class/functions.php';
require_once dirname(__FILE__).'/../class/user.class.php';

$a = session_id();if(empty($a)) session_start();
mysql_safer();
$logat = is_logat();
///print_r($_SESSION);
if($logat == 0)
    die("Nu v-ati logat");
else
{
    if( $_SESSION['logat'] == "admin" )
    {
        //echo "sunteti admin";     
        $user=unserialize($_SESSION['userc']);
        //echo list_rez();
        $admin=1;
        
    }
    else die("Interzis utilizatorilor normali!(Nu aveti drepturi!)");
    
}


?>
<html>
    <body>
<?
                            $search="<div id='search_rez'>";
                            $perioade=  pt_rezervari("perioade", "perioada");
                            $sali=  pt_rezervari("sali", "sala");
                            $categorii= pt_rezervari("categorii", "categoria");
                            $anii=pt_rezervari("ani", "an");
                            $search.="</div>";
                                             
                   ?>
                    <form  method=post>
                    <?
                    echo $perioade;
                    echo $sali;
                    
                    ?>
                    <input type="hidden" name="r" id="r" value="<?echo $_GET['r'] ?>"/> 
                    Motiv: <input type="text" name="motiv" value=""/> 
                    Data: <input type="text"  id="datepicker" name="data" value=""/>
                    Status: <select name="status"><option value='1'>Activ</option> <option value='0'>Inactiv</option> </select>
                    <br/>
                    <a href="#" class="grey-button pcb"><span id="rez_submit">Submit</span></a> <br/> <br/>
                    </form>

        <script src="<?echo $path; ?>js/jquery.min_1.js" type="text/javascript"></script> 
        <script src="<?echo $path; ?>js/jquery-ui.min.js" type="text/javascript"></script>
	<script src="<?echo $path; ?>js/jquery.ui.core.js"></script>
	<script src="<?echo $path; ?>js/jquery.ui.widget.js"></script>
	<script src="<?echo $path; ?>js/jquery.ui.datepicker.js"></script>
	<link rel="stylesheet" href="<?echo $path; ?>js/datepick.css">
        <link rel="stylesheet" type="text/css" href="<?echo $path; ?>js/jquery-ui.css" />
	
	<script>
	$(function() {
		$( "#datepicker" ).datepicker({ dateFormat: 'yy-mm-dd' });
                
	});
	</script>
    <script type="text/javascript">
        
        $(window).load(function(event){
            //alert('hah');
            var r=$('#r').val();
              data={
                     rid : r

                 };
       
       url="../class/call.ajax.php?action=get_rezervare&r="+r;
         //alert(r);
        $.getJSON(url,data,function(result){
             
            // alert(data.fid);
            // alert(result.RID);
           $("select[name$=perioada] option[value='"+result.PID+"']").attr('selected', 'selected');
           $("select[name$=sala] option[value='"+result.OID+"']").attr('selected', 'selected');
           $("select[name$=status] option[value='"+result.STATUS+"']").attr('selected', 'selected');
           $("input[name$=motiv]").val(result.motiv);
           $("input[name$=data]").val(result.data);
        });  

       return false; 
      });
      

    $("#rez_submit").click(function(event){
     event.preventDefault();
     data={
            data : $("input[name$=data]").val(),
            perioada : $("select[name$=perioada] option:selected").val(),
            status : $("select[name$=status] option:selected").val(),
            sala : $("select[name$=sala] option:selected").val(),
            motiv : $("input[name$=motiv]").val(),
            r : $("input[name$=r]").val()

        };
       
       
       url="../class/call.ajax.php?action=upd_rez";
        $.post(url,data,function(result){
             alert(result);
             window.close(); 
        },"html");     


        return false;
      });
      
    </script>       
    </body>
    
    
 
</html>